package com.ruoyi.web.controller.production.regulator;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.production.domain.regulator.RegulatorApply;
import com.ruoyi.production.service.regulator.IRegulatorApplyService;
import io.netty.util.internal.UnstableApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调节剂申请Controller
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@RestController
@RequestMapping("/regulator/apply")
@Api(value = "调节剂申请",tags = "调节剂申请相关API")
public class RegulatorApplyController extends BaseController
{
    @Autowired
    private IRegulatorApplyService regulatorApplyService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询调节剂申请列表
     */
    @PreAuthorize("@ss.hasPermi('regulator:apply:list')")
    @GetMapping("/list")
    @ApiOperation("获取调节剂申请列表")
    @ApiImplicitParam(name = "regulatorApply", value = "调节剂申请实体", paramType = "body", dataType = "RegulatorApply")
    public TableDataInfo list(RegulatorApply regulatorApply)
    {
        startPage();
        List<RegulatorApply> list = regulatorApplyService.selectRegulatorApplyList(regulatorApply);
        return getDataTable(list);
    }

    /**
     * 导出调节剂申请列表
     */
    @PreAuthorize("@ss.hasPermi('regulator:apply:export')")
    @Log(title = "调节剂申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出调节剂申请数据")
    @ApiImplicitParam(name = "regulatorApply", value = "调节剂申请实体", paramType = "body", dataType = "RegulatorApply")
    public AjaxResult export(RegulatorApply regulatorApply)
    {
        List<RegulatorApply> list = regulatorApplyService.selectRegulatorApplyList(regulatorApply);
        ExcelUtil<RegulatorApply> util = new ExcelUtil<RegulatorApply>(RegulatorApply.class);
        return util.exportExcel(list, "调节剂申请数据");
    }

    /**
     * 获取调节剂申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('regulator:apply:query')")
    @GetMapping(value = "/{regulatorApplyId}")
    @ApiOperation("获取调节剂申请详细信息")
    @ApiImplicitParam(name = "regulatorApplyId", value = "调节剂申请主键", paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("regulatorApplyId") Long regulatorApplyId)
    {
        return AjaxResult.success(regulatorApplyService.selectRegulatorApplyById(regulatorApplyId));
    }

    /**
     * 新增调节剂申请
     */
    @PreAuthorize("@ss.hasPermi('regulator:apply:add')")
    @Log(title = "调节剂申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增调节剂申请信息")
    @ApiImplicitParam(name = "regulatorApply", value = "调节剂申请实体类", paramType = "body", dataType = "RegulatorApply")
    public AjaxResult add(@RequestBody RegulatorApply regulatorApply)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        regulatorApply.setUserId(loginUser.getUser().getUserId());
        return toAjax(regulatorApplyService.insertRegulatorApply(regulatorApply));
    }

    /**
     * 修改调节剂申请
     */
    @PreAuthorize("@ss.hasAnyPermi('regulator:apply:edit,regulator:apply:permit1,regulator:apply:permit2')")
    @Log(title = "调节剂申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改调节剂申请信息")
    @ApiImplicitParam(name = "regulatorApply", value = "调节剂申请实体类", paramType = "body", dataType = "RegulatorApply")
    public AjaxResult edit(@RequestBody RegulatorApply regulatorApply)
    {
        return toAjax(regulatorApplyService.updateRegulatorApply(regulatorApply));
    }

    /**
     * 删除调节剂申请
     */
    @PreAuthorize("@ss.hasPermi('regulator:apply:remove')")
    @Log(title = "调节剂申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regulatorApplyIds}")
    @ApiOperation("删除调节剂申请信息")
    @ApiImplicitParam(name = "regulatorApplyIds", value = "调节剂申请主键数组", paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] regulatorApplyIds)
    {
        return toAjax(regulatorApplyService.deleteRegulatorApplyByIds(regulatorApplyIds));
    }
}
